package com.fhzn.boss.tools;

/**
 * @author 老顾
 * @apiNote
 * @since 2024/1/31
 */
public class PasswordUtils {

    /**
     * 移位数
     */
    private static final int SHIFT = 3;

    /**
     * 加密
     *
     * @param input 输入密码
     * @return 加密后的密码
     */
    public static String encrypt(String input) {
        StringBuilder encrypted = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (Character.isLetter(c)) {
                c = (char) (c + SHIFT);
                if (!Character.isLetter(c)) {
                    c = (char) (c - 26);
                }
            }
            encrypted.append(c);
        }
        return encrypted.toString();
    }

    /**
     * 解密
     *
     * @param input 输入密码
     * @return 解密后的密码
     */
    public static String decrypt(String input) {
        StringBuilder decrypted = new StringBuilder();
        for (int i = 0; i < input.length(); i++) {
            char c = input.charAt(i);
            if (Character.isLetter(c)) {
                c = (char) (c - SHIFT);
                if (!Character.isLetter(c)) {
                    c = (char) (c + 26);
                }
            }
            decrypted.append(c);
        }
        return decrypted.toString();
    }
}
